package com.yang.beans;

import com.yang.beans.beanclass.Order;
import com.yang.beans.beanclass.SpringFactoriesBean;
import com.yang.beans.beanclass.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ImportResource;

import java.util.Map;

@SpringBootApplication
@ImportResource(locations = {"classpath:beans.xml"})
public class BeansApplication {

    @Autowired
    SpringFactoriesBean springFactoriesBean;

    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(BeansApplication.class);
        System.out.println("---------------beans开始------------------");
        printBean(run, User.class);
        printBean(run, Order.class);
        printBean(run, SpringFactoriesBean.class);

        System.out.println("---------------beans结束------------------");

    }

    private static void printBean(ConfigurableApplicationContext run, Class tclass) {
        Map<String, User> beansOfType = run.getBeansOfType(tclass);
        for (Map.Entry<String, User> stringUserEntry : beansOfType.entrySet()) {
            System.out.println(stringUserEntry);
        }
    }
}
